import React, {} from 'react';
import styles from './index.less';
import { connect } from '@@/plugin-dva/exports';
import {cloneDeep} from "lodash";
import {Modal} from "antd";
import {stopRequest} from "@/utils/requsetApi";
// const { REACT_APP_ENV} = process.env

const TabTop=({dispatch,dialogFlag,backMessageListGz,backMessageListAI,messageList,titleGz,titleAI,title,dialogueIdGz,dialogueIdAI,dialogueId,isLoading})=>{
  let tabList = [];
  tabList = ["规则分析","AI取数(β版)"]
  function changeTab(index) {
    dispatch({
      type:"intellectAssistant/updateState",
      payload:{
        dialogFlag:index,
        [index==="0"?"backMessageListAI":"backMessageListGz"]:cloneDeep(messageList),
        messageList:index==="0"?cloneDeep(backMessageListGz):cloneDeep(backMessageListAI),
        [index==="0"?"titleAI":"titleGz"]:title,
        title:index==="0"?titleGz:titleAI,
        [index==="0"?"dialogueIdAI":"dialogueIdGz"]:dialogueId,
        dialogueId:index==="0"?dialogueIdGz:dialogueIdAI,
        isLoading:false,
      },
    })
  }
function tabHandleClick(index){
  if(isLoading){
    return Modal.confirm({
      title:"提示",
      content:"AI助手正在回答中，请耐心等待",
      centered:true,
      okText:"提问新问题",
      onOk(){
        return new Promise((resolve=>{
          resolve()
          stopRequest().then(() =>{
            changeTab(index)
          } )
        }))
      }
    })
  }
  changeTab(index)
}
  return  <div  className={styles.tabWrap}>
    {tabList.map((item,index)=> {
      return <div onClick={()=>tabHandleClick(index.toString())}  key={index} style={{color:index.toString()===dialogFlag?"#1067ee":"#8c8e9c",backgroundColor:index.toString()===dialogFlag?"#ecedfd":"#fff"}} className={styles.item}>{item}</div>
    })}
  </div>
}
export default connect(({intellectAssistant}) => ({
  dialogFlag: intellectAssistant.dialogFlag,
  messageList: intellectAssistant.messageList,
  backMessageListGz: intellectAssistant.backMessageListGz,
  backMessageListAI: intellectAssistant.backMessageListAI,
  titleGz: intellectAssistant.titleGz,
  titleAI: intellectAssistant.titleAI,
  title: intellectAssistant.title,
  dialogueId: intellectAssistant.dialogueId,
  dialogueIdGz: intellectAssistant.dialogueIdGz,
  dialogueIdAI: intellectAssistant.dialogueIdAI,
  isLoading: intellectAssistant.isLoading,
}))(TabTop);
